<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>雨花内容管理</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link href="../../static/css/uploadify.css" rel="stylesheet" type="text/css"/>


<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script src="../../static/js/jquery.uploadify.js" type="text/javascript"></script>

<%
String []nonceObj=ConstantUtils.getNonceObject();
%>

<script type="text/javascript">
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: '../../industry/yhUser_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_cc_id',title:'ID',align:'center',width:50},
					{field:'user_name',title:'用户名称',align:'center',width:150},
					{field:'home_name',title:'雨花家园名称',align:'center',width:150},
					{field:'com_name',title:'社区',align:'center',width:150},
					{field:'f_yh_status',title:'状态',align:'center',width:80,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="上线";
							} else if(value==2||value==16||value==14){
								status="待审核";
							} else if(value==4||value==13||value==15){
								status="审核未通过";
							}
							return status;
						}	
					},
					{field:'open_send_food_service',title:'送餐服务',align:'center',width:80,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==0){
								status="未开通";
							}else if(value==1){
								status="开通";
							}
							return status;
						}
					},

					{field:'apply_status',title:'申请状态',align:'center',width:80,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==0){
								status="未申请";
							}else if(value==1){
								status="审核中";
							}else if(value==2){
								status="审核通过";
							}else if(value==3){
								status="拒绝";
							}
							return status;
						}
					},

					{field:'f_cc_remark',title:'审核描述',align:'center',width:150,
						formatter:function(value,row,index) {
						var str = "";
						if(row.f_yh_status==1){
							str = "审核结束";
						}else if(row.f_yh_status==2){
							str = "市公司审核中";
						}else if(row.f_yh_status==16){
							str = "省公司审核中";
						}else if(row.f_yh_status==14){
							str = "牌照审核中";
						}
						else{
							if(value){
								str=value;
							}
						}
						return str;
						}	
					},
					/* {field:'省电信审核时间',title:'省电信审核时间',align:'center',width:150},
					{field:'文广审核时间',title:'文广审核时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}	
					}, */
					{field:'_parentId',title:'操作',align:'center',width:300,
						formatter:function(value,row,index){
							str ="";
							str= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a>';
							if(row.f_yh_status==2||row.f_yh_status==13||row.f_yh_status==4|| row.f_yh_status==1){
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';	
							}
				    		//str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">详情</span></span></a>';
			    			//市公司
				    		<limits:uiAuth url="review_yh_content.do">
					    		<limits:uiAuth url="city_yh_review_power">
						    		if(row.f_yh_status==2 || row.f_yh_status==4) {
						    			str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="review(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">市公司审核</span></span></a>';
						    		}
					    		</limits:uiAuth>
					    		//省公司审核
					    		<limits:uiAuth url="province_yh_review_power">
					    			if(row.f_yh_status==16 || row.f_yh_status==13) {
					    				str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="review(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">省公司审核</span></span></a>';
					    			}
					    		</limits:uiAuth>
				    		</limits:uiAuth>
					    	return str;
				    	}
					}
				]],
				singleSelect:true,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/login.do';
						    return false;
						}});
					}
				}
			});
		}
	
		function getGueryParams(){
			return {
				user_name:$("#user_name").val(),
				f_yh_status:$("#f_yh_status").val(),
				home_name:$("#home_name").val(),
				f_cc_companyname:$("#f_cc_companyname").val()
			};
		}
		
		$(function(){
			$.ajax({
				url:"../../pms/org_list.do",
				success:function(data) {
					data = JSON.parse(data);
					var str = "";
					for(var i=0;i<data.length;i++) {
						str+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
					}
					$("#f_cc_companyid").append(str);
					
					$("#orgSpan").append($("#f_cc_companyid").clone(true));
				}
			});
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			
			onClickBtnDelete = function(id){
				$.messager.confirm('确定删除节目','确定删除节目么?',function(r){
					if(r){
						app_ajax('../../content/delete_content.do?f_cc_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
						'',
						function(msg){
							if(msg.success) {
								alert("删除成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert("删除异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
							window.location.reload();
						}
						);
					}
				});
			};
			
			$("#chooseOption1").on("change", function(){
				if($(this).val() == 1){
					$("#chooseOption2").show();
				} else {
					$("#chooseOption2").hide();
				}
			});
			
			
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function _resert(){
			$("#f_cc_name").val("");
			$("#f_yh_status").val("");
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function edit(id){
			openDialog($("#dlg"),'content_update.jsp?f_cc_id='+id);
		}
		
		function show(id){
			openDialog($('#dlg'),'content_info.jsp?f_cc_id='+id);
		}
		
		function add(){
			openDialog($('#dlg'),'content_add.jsp');
		}
		
		function series(id) {
			openDialog($('#seriesdlg'),'series_list.jsp?f_cc_id='+id);
		}
		
		function review(id) {
			openDialog($('#dlg'),'content_review.jsp?f_cc_id='+id);
		}
		
		function bind(id) {
			openDialog($('#dlg'),'content_bind.jsp?f_cc_id='+id);
		}
		
		function batchReview() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				for(var i=0;i<rows.length;i++) {
					if(rows[i].f_yh_status == 2 || rows[i].f_yh_status == 4/* || rows[i].f_yh_status == 7 */)
						ids += rows[i].f_cc_id + ',';
				}
				ids = ids.substring(0, ids.length - 1);
				if(ids.length <= 0) {
					alert("请选择至少一条未上线的节目");
				} else {
					$.ajax({
						url:"batch_review_content.do",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
						}
					});
				}
			}
		}
		
		function batchUnReview() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				if(confirm("确认是否下线这些记录？")){
					for(var i=0;i<rows.length;i++) {
						ids += rows[i].f_cc_id + ',';
					}
					ids = ids.substring(0, ids.length - 1);
					$.ajax({
						url:"batch_unreview_content.do?stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
							window.location.reload();
						}
					});
					
				}
			}
		}
		
		function batchDelete() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				if(confirm("确认是否删除这些记录？")){
					for(var i=0;i<rows.length;i++) {
						ids += rows[i].f_cc_id + ',';
					}
					ids = ids.substring(0, ids.length - 1);
					$.ajax({
						url:"batch_delete_content.do?stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
							window.location.reload();
						}
					});
				}
			}
		}
		function contentSelectAdvertisement(id){
			openDialog($('#dlg'),'content_advertisement.jsp?f_cc_id='+id+"&f_ccadver_type=2");
		}
		function bind() {
			openDialog($('#org_list'),'../behavior_control/org_update.jsp?idField=f_cc_companyid&nameField=f_cc_company_name');
		}
		function resert(){
			$("#f_cc_company_name").val("");
			$("#f_cc_companyid").val("");
		}
	</script>
</head>
<body onload="load();" style="width: 100%;">
	<input type="hidden" id="sessionId" value="${pageContext.session.id}" />
	<table id="easyui-datagrid" title="节目列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="left" width="7%">用户名称:</td>
						<td align="left" width="15%"><input name="user_name" id="user_name" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="left" width="7%">状态:</td>
						<td align="left" width="10%">
							<select id="f_yh_status" name="f_yh_status">
									<option value="0">请选择</option>
									<option value="1">上线</option>
									<option value="2">市级审核中</option>
									<option value="4">市审核未通过</option>
									<option value="13">省审核未通过</option>
									<option value="16">省级审核中</option>
							</select>
						</td>
						
						<td align="left" width="10%">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-add', plain:true" onclick="add()">增加节目</a>
						</td>
					</tr>
					<tr>
						<td align="left" width="7%">雨花家园名称:</td>
						<td align="left" width="15%"><input name="home_name" id="home_name" style="width: 150px;" onkeydown="onpress();" /></td>

						<td align="left" width="10%">社区名称:</td>
						<td align="left" width="15%"><input name="com_name" id="com_name" style="width: 150px;" onkeydown="onpress();" /></td>

						<%--	<td  align="left" width="10%">
							行业客户:
						</td>
						<td align="left" width="20%">
							<input name="f_cc_company_name" id="f_cc_company_name" readonly="readonly"	style="width: 150px;" value="" class="yl_inp yw_name" />
							<input name="f_cc_companyid" id="f_cc_companyid" type="hidden" value="" />  
							<input name="status" id="status" type="hidden" value="nochange" />  
							<!-- <select id="f_cc_companyid" name="f_cc_companyid" style="width: 150px;">
							</select> -->
							<!-- <span id="f_cc_companyid_tip" class="tip"></span> -->
							<a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);" onclick="resert()">空选</a>
							<a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
								onclick="bind();">选择</a>
						</td>--%>
						<td align="left" width="10%">
							<limits:uiAuth url="yhUser_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search', plain:true"
									onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
							</limits:uiAuth>
						</td>
						
						
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 950px; height: 600px; padding-top: 0px;"
		data-options="title:'节目管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="seriesdlg" class="easyui-dialog"
		style="width: 1000px; height: 600px; padding-top: 0px;"
		data-options="title:'剧集管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="org_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<div id="win" class="easyui-window" closed="true" modal="true" iconCls="icon-save" style="width:440px; height: 290px; left: 50%px;top: 30%;" title="节目批量导入">
		<div class="easyui-layout" fit="true">
			<div region="north" border="true" style="height: 40;">
				<a class="easyui-linkbutton" style="line-height: 20px; padding-bottom: 3px;" iconCls="icon-undo" plain="true" href="../../static/excel/节目批量导入模版.xlsx">下载模版&nbsp;</a>
			</div>
			
			<div region="center" border="true">
				<div>
					<p>
						<font size="6" style="font-weight: bold;color: gray;">批量导入说明:</font><br/>
						&nbsp;&nbsp;1. 选择组织(必须):<span id="orgSpan"></span><br/>
						&nbsp;&nbsp;2. 导入选项:&nbsp;&nbsp;&nbsp;<select id="chooseOption1" name="chooseOption1">
																	<option value="0">默认</option>
																	<option value="1">帐号导入(去重)</option>
																</select>
																<select id="chooseOption2" name="chooseOption2" style="display: none;">
																	<option value="1">电视剧</option>
																	<option value="2">电影</option>
																	<option value="3">直播</option>
																	<option value="4">图文</option>
																	<option value="5">链接</option>
																	<option value="7">转码视频</option>
																	<option value="20">组织模板</option>
																	<option value="100" selected="selected">业务账号</option>
																	<option value="110">其他</option>
																</select><br/>
						&nbsp;&nbsp;3. 节目类型 1:电视剧, 2:电影, 3:直播, 4:图文, 5:链接, 7:转码视频, 100:业务账号, 110:其他<br/>
						&nbsp;&nbsp;4. 是否完结 未完结:0, 完结:1 <br/>
						&nbsp;&nbsp;5. 所有节目都收费<br/>
						&nbsp;&nbsp;6. 上线时间为当前时间<br/>
						&nbsp;&nbsp;7. 下线时间2099-12-31 23:59:59<br/>
					</p>
				</div>
			</div>
			
			<div region="south" border="false" style="text-align:left;height:40px;padding: 3px">
				<input id="uploadFile2"  type="file" name="file"/>
			</div>
			
		</div>
	</div>
	

<script type="text/javascript">
	$(function(){
		$('#win').window({
	       onBeforeClose:function(){ 
				//window.location.reload();	
	       }
		});
		initFileUpload("#uploadFile2", {});
	});
	
	function batch_add(){
		$('#win').window('open');
	}
	
	function initFileUpload(inputId, params){
		var action = 'insert_batch_content.do?stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>;jsessionid='+$("#sessionId").val();
		$(inputId).uploadify({
			'swf'           :'../../swf/uploadify.swf',
			'uploader'      :action,
			'formData'      :params,
			'fileObjName'   :'uploadify',
			'cancelImg' 	:"../../imgs/uploadify-cancel.png",
			'queueId'		:"fileQueue",
			'fileTypeDesc'  :"Excel File",
			'fileTypeExts'	:"*.xls; *.xlsx",//限制文件类型
			'auto'			:true,//是否自动上传
			'multi'			:false,//是否允许多文件上传
			'buttonText'	:"导入文档",
			'method'		:"POST",
			'onInit'        : function(){
			},
			'onUploadStart' : function(file){
				var orgId = $("#win #f_cc_companyid").val();
				if(!(orgId && orgId > 0)){
					$(inputId).uploadify('cancel');
					alert("请选择组织！");
				}else{
					$(inputId).uploadify('settings','formData', {"f_cc_companyid" : orgId, "chooseOption1" : $("#win #chooseOption1").val(), "chooseOption2" : $("#win #chooseOption2").val()});
					jQuery.messager.alert('批量导入','批量导入开始, 操作结果请稍后.');
				}
			},
			'onUploadSuccess' : function(file,data,response) {
				if(data != null && data != undefined && data != ''){
					jQuery.messager.alert('批量导入',data);
				}
			},
			'onUploadError' : function(file, errorCode, errorMsg, errorString) {
				if(errorMsg == '302'){
					jQuery.messager.alert('批量导入','批量导入失败，请检查登录状态或者无此权限!');
				}
	        }
		});
	}
	function exportExcel(){
		var pager = $("#easyui-datagrid").datagrid("getPager").data("pagination").options;;
		var page=pager.pageNumber;
		var rows=pager.pageSize;
		var f_cc_name=$("#f_cc_name").val();
		var f_yh_status=$("#f_yh_status").val();
		var f_cc_type=$("#f_cc_type").val();
		var f_cc_companyid=$("#f_cc_companyid").val();
		var url="content_excel_list.do?f_cc_name="+f_cc_name+"&f_cc_status="+f_cc_status+"&f_cc_type="+f_cc_type+"&f_cc_companyid="+f_cc_companyid+"&page="+page+"&rows="+rows;
		window.open(url);
	}
</script>
	
	
	
</body>
</html>